<include file="public@storage"/>
</head>
<body>
<div class="container body-content" style="margin-top:20px;width: 100%">
    <div class="panel panel-info" style="margin-bottom: 0.5rem">
        <div class="panel-heading">
            <span id="storageName">
            <button id = "return" style="background-color:rgb(51, 122, 183);border: none ;display: none" onclick="history.go(-1)"><span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span></button>
            {$storageInfo[0]['name']}</span>货架管理
        </div>

        <input type="hidden" id="storageUuid" value="{$storageInfo[0]['uuid']}">
        <input type="hidden" id="returnValue" value="{$history}">
        <div class="panel-body">
            <div class="row">
                <div class="col-sm-12">
                    <div id="toolbar" class="btn-group">
                        <button id="addSelf" class="btn btn-info" style="margin-left: 1rem; width: 10rem"
                                onclick="add()">添加货架
                        </button>
                        <select id="selectStorage" class="btn btn-info" style="margin-left: 1rem; width: 10rem"
                                onchange="changeStorage()">
                            <option value="">请选择仓库</option>
                            <volist id="uuid" name="storageInfo" id="value">
                                <option value="{$value['uuid']}">{$value['name']}</option>
                            </volist>
                        </select>
                    </div>
                    <table id="table"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="__STATIC__/storage/js/common/selectStorage.js"></script>
<script>
    var storageUuid = $("#storageUuid").val();
    var returnValue = $("#returnValue").val();

    $(function () {
        if ($("#storageUuid").val() === '') {
            console.log('select');
            $("#selectStorage").show();
            $("#addSelf").hide();
        } else {
            console.log('add');
            $("#selectStorage").hide();
            $("#addSelf").show();
        }
        console.log(returnValue);
        if(returnValue == 1){
            $("#return").show();
        }
        init();
    });

    function init() {
        var url = "{:url('/storage/Shelf/getShelf')}?&storageUuid=" + storageUuid;
        var columns = [
            {
                title: '序号',
                width: 50,
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },
            {
                title: 'uuid',
                field: 'uuid',
                visible: false
            },
            {
                title: '仓库uuid',
                field: 'storage_uuid',
                visible: false
            },
            {
                title: '货架号',
                field: 'shelves_code',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '层数',
                field: 'floor',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '每层站位数',
                field: 'floor_count',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '总站位数',
                field: 'seat_count',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '所属仓库',
                field: 'name',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '操作',
                field: 'uuid',
                align: "center",
                valign: 'middle',
                formatter: function (value, row) {
                    var html = '<a href="{:url(\'/storage/Seat/index\')}?shelfUuid=' + row.uuid + '&storageUuid=' + storageUuid + '">站位</a>';
                    html += '&nbsp&nbsp|&nbsp&nbsp';
                    html += '<a onclick="deleteShelf(this)" href="javascript:void(0);" data-uuid="' + row.uuid + '"> 删除</a>';
                    return html;
                }
            }
        ];
        initTable(url, columns, 'server', InitSubTable);
        setColumn();
    }


    InitSubTable = function (index, row, $detail) {
        var tableId = "cur_table_"+index;
        $detail.html('<table id="'+ tableId+ '"></table>').find('table');
        var url = '{:url("storage/Seat/getSeat")}?shelfUuid=' + row.uuid;
        var column = [
            {
                title: '序号',
                width: 50,
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },
            {
                title: 'uuid',
                field: 'uuid',
                align: "center",
                visible: false
            },
            {
                title: '站位号',
                field: 'seat_code',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '设备码',
                field: 'seat_id',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '状态',
                field: 'status',
                align: "center",

                filter: {
                    type: 'input'
                }, formatter: function (value) {
                    if (value === 0) {
                        return '正常';
                    } else {
                        return '<span style="color:#ff0000;font-weight: bolder">' + '异常' + '</span>';
                    }
                }
            }
        ];
        initSubTable(tableId,url, column, 'server');
    };

    function setColumn() {
        if (storageUuid === '') {
            $('#table').bootstrapTable('showColumn', 'name');
        } else {
            $('#table').bootstrapTable('hideColumn', 'name');
        }
    }

    function add() {
        window.open("{:url('/storage/Shelf/add')}?storageUuid=" + storageUuid, '_self');
    }

    deleteShelf = function (that) {
        var uuid = $(that).data('uuid');
        var param = {uuid: uuid};
        var success = function (ret) {
            if (ret.success === false) {
                layer.msg(ret.message);
            } else {
                $('#table').bootstrapTable('refresh');
            }
        };
        ajax('get', '/storage/Shelf/deleteShelf', param, success);
    }


</script>
</html>